﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using System.IO;

using RHFrameWork;

namespace TestProjectBase
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        public string Url { get; set; }
        public WebSiteProcess SiteProcess { get; set; }
        public UserInfo User { get; set; }
        public Assembly ProcessAssembly { get; set; }

        private void MainForm_Load(object sender, EventArgs e)
        {
             
        }

        public void CreateTest(string url, Assembly assem,string strUserInfo)
        {
            this.Url = url;
            this.ProcessAssembly = assem;
            this.SiteProcess = new WebSiteProcess(assem);
            this.User = new UserInfo();
            this.User.Load(strUserInfo);

            wb.Navigate(this.Url);
        }

        private void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            if (SiteProcess != null)
            {
                if(e.Url.Host =="")
                {
                    SiteProcess.Process(wb.Document.Url, wb.Document, User);
                }else
                {
                    SiteProcess.Process(e.Url, wb.Document, User);
                }
                
            }
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            wb.Navigate("about:blank");
            wb.Navigate(this.Url);
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if (ProcessAssembly == null)
            {
                return;
            }

            string strPath = ProcessAssembly.CodeBase.Substring(8);

            Byte[] ary = File.ReadAllBytes(strPath);

            string strData = Convert.ToBase64String(ary);

            File.WriteAllText(@"C:\zhw.proc", strData);
        }


    }
}
